﻿using System.Collections.Generic;
using FluentAssertions;
using Xunit;
using Xunit.Extensions;
using Calimbra.Addin.Functions;
using Calimbra.Addin.Messages;

namespace Calimbra.Addin.test
{
    public class Identify_function_units_Test
    {
        [Theory,
        InlineData(".in A","A","in"),
        InlineData("in A","A","in"),
        InlineData(".in\tA","A","in"),
        InlineData(".in \tA","A","in"),
        InlineData(".in\t A","A","in"),
        InlineData(".in \t A", "A", "in")]
        public void Space_and_tab_delemiter(string inputRow,string expectedFunctionName, string expectedInputPortName)
        {
            var sut = new Identify_function_units();
            var actualResult = new List<FunctionUnit>();
            sut.Result += r => actualResult = r;

            sut.Check(inputRow);
            sut.FireStatus();

            actualResult.Should().HaveCount(1)
                .And.Contain(item => item.Name == expectedFunctionName);
            actualResult[0].InputPortNames.Should().HaveCount(1).And.Contain(i=>i == expectedInputPortName);
            actualResult[0].OutputPortNames.Should().HaveCount(0);
        }


        [Theory,
        InlineData("A B", "A", "out", "B", "in"),
        InlineData("A B.in", "A", "out", "B", "in"),
        InlineData("A.out B.in", "A", "out", "B", "in"),
        InlineData("A.outX B", "A", "outX", "B", "in"),
        InlineData("A.outX B.in", "A", "outX", "B", "in"),
        InlineData("A B.inX", "A", "out", "B", "inX")]
        public void Output_and_input_ports(string inputRow, string expectedFunctionName1, string expectedOutputPortName, string expectedFunctionName2, string expectedInputPortName)
        {
            var sut = new Identify_function_units();
            var actualResult = new List<FunctionUnit>();
            sut.Result += r => actualResult = r;

            sut.Check(inputRow);
            sut.FireStatus();

            actualResult.Should().HaveCount(2)
                .And.Contain(item => item.Name == expectedFunctionName1)
                .And.Contain(item => item.Name == expectedFunctionName2);
            actualResult[0].InputPortNames.Should().HaveCount(0);
            actualResult[0].OutputPortNames.Should().HaveCount(1)
                .And.Contain(i => i == expectedOutputPortName);
            actualResult[1].OutputPortNames.Should().HaveCount(0);
            actualResult[1].InputPortNames.Should().HaveCount(1)
                .And.Contain(i => i == expectedInputPortName);
        }
    }
}
